package com.nulldev.util.media.nAV.internal;

import java.awt.Image;

import com.nulldev.util.graphics.renderIt.api.renderItGraphicsInterface;
import com.nulldev.util.graphics.renderIt.api.envcaps.renderItOperations;
import com.nulldev.util.media.nAV.renderIt.IVideoSurface;

public interface IDecodedFrame {

	public static enum FrameType {
		VIDEO,
		AUDIO,
	}

	public Object getNativeObject();

	public Image getImage();

	public FrameType getFrameType();

	public boolean isValid();

	public int width();

	public int height();

	public default int bitrate() {
		return 0;
	}

	public default long decodingTime() {
		return 0L;
	}

	public default IVideoSurface surface() {
		return new IVideoSurface() {

			@Override
			public int width() {
				return IDecodedFrame.this.width();
			}

			@Override
			public int height() {
				return IDecodedFrame.this.height();
			}

			@Override
			public void renderTo(final renderItGraphicsInterface ri, int x, int y, int width, int height) {
				if (ri.supportsOperations(renderItOperations.RIT_SWING_image_draw)) {
					ri.swing_drawImage(getImage(), x, y, width, height);
				} else {
					throw new UnsupportedOperationException("TODO: Use AWT_draw_image or EXT_draw_image");
				}
			}
		};
	}
}
